import axios from 'axios'
import {ref} from 'vue'

export default function useUrlLoader<T>(url: string) {
  const result = ref<T>()
  const loading = ref(true)
  const errorMsg = ref<string>()

  axios(url).then(
    response => {
      loading.value = false
      result.value = response.data
    },
    
    error => {
      loading.value = false
      errorMsg.value = error.message
    }
  )

  return {
    result,
    loading,
    errorMsg
  }
}